﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2013-08-26 14:30
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BassDrop.Core.Common;
using BassDrop.Core.Common.Localization;

namespace BassDrop.DesktopClient.UI.Views
{
	/// <summary>
	/// View / page for showing the about page / program information
	/// </summary>
	public partial class AboutView : ContentViewBase
	{
		public AboutView()
		{
			InitializeComponent();

			IsVisibleChanged += AboutView_IsVisibleChanged;
		}

		void AboutView_IsVisibleChanged( object sender, DependencyPropertyChangedEventArgs e )
		{
			TextBlockAssemblyProduct.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyProductFormat, AssemblyProduct );
			TextBlockAssemblyVersion.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyVersionFormat, AssemblyVersion );
			TextBlockAssemblyCompany.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyCompanyFormat, AssemblyCompany );
			TextBlockAssemblyCopyright.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyCopyrightFormat, AssemblyCopyright );
			TextBlockAssemblyDescription.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyDescriptionFormat, AssemblyDescription );

			StackPanelDllInfos.Children.Clear();

			foreach ( var item in Controller.Instance.PluginManager.GetPlugins() )
			{
				TextBlock product = new TextBlock();
				product.TextWrapping = TextWrapping.Wrap;
				product.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyProductFormat, item.Name );
				StackPanelDllInfos.Children.Add( product );

				TextBlock version = new TextBlock();
				version.TextWrapping = TextWrapping.Wrap;
				version.Text = String.Format( Strings.LabelAboutViewTextBlockAssemblyVersionFormat, item.Version );
				StackPanelDllInfos.Children.Add( version );

				// TODO: további infók

				StackPanelDllInfos.Children.Add( new TextBlock() );
			}
		}

		private void Hyperlink_RequestNavigate( object sender, RequestNavigateEventArgs e )
		{
			Process.Start( e.Uri.ToString() );
		}

		#region Assembly Attribute Accessors

		/// <summary>
		/// Gets the assembly version of the DesktopClient
		/// </summary>
		public string AssemblyVersion
		{
			get
			{
				return Assembly.GetExecutingAssembly().GetName().Version.ToString();
			}
		}

		/// <summary>
		/// Gets the assembly description of the DesktopClient
		/// </summary>
		public string AssemblyDescription
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes( typeof( AssemblyDescriptionAttribute ), false );
				if ( attributes.Length == 0 )
				{
					return "";
				}
				return ((AssemblyDescriptionAttribute) attributes[0]).Description;
			}
		}

		/// <summary>
		/// Gets the assembly product of the DesktopClient
		/// </summary>
		public string AssemblyProduct
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes( typeof( AssemblyProductAttribute ), false );
				if ( attributes.Length == 0 )
				{
					return "";
				}
				return ((AssemblyProductAttribute) attributes[0]).Product;
			}
		}

		/// <summary>
		/// Gets the assembly copyright of the DesktopClient
		/// </summary>
		public string AssemblyCopyright
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes( typeof( AssemblyCopyrightAttribute ), false );
				if ( attributes.Length == 0 )
				{
					return "";
				}
				return ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
			}
		}

		/// <summary>
		/// Gets the assembly company of the DesktopClient
		/// </summary>
		public string AssemblyCompany
		{
			get
			{
				object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes( typeof( AssemblyCompanyAttribute ), false );
				if ( attributes.Length == 0 )
				{
					return "";
				}
				return ((AssemblyCompanyAttribute) attributes[0]).Company;
			}
		}

		#endregion Assembly Attribute Accessors
	}
}
